home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / C / Blitter / RamboWorm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-09  |  3.7 KB  |  165 lines

  1. /*
  2. ** Name:      Blit Worm Demo
  3. ** Author:    Paul Manias
  4. ** Copyright: DreamWorld Productions (c) 1996-1997.
  5. ** SAS/C:     1> sc BlitWorm.c link startup=LIB:gms.o data=far nostackcheck
  6. ** Dice:      1> dcc -l0 -mD gms.o BlitWorm.c -o BlitWorm
  7. **
  8. ** Blits a Worm to screen using a bob structure.  This version does not
  9. ** include the sound from the assembler version.
  10. **
  11. */
  12.  
  13. #include <proto/games.h>
  14.  
  15. extern struct GMSBase *GMSBase;
  16. ULONG PREFSNAME = DEFAULT;
  17.  
  18. struct GameScreen  *screen;
  19. struct Restorelist *restore;
  20. struct Bob         *Worm;
  21.  
  22. #define TRUE 1
  23. #define FALSE 0
  24.  
  25. void Demo(void);
  26. void Wrap(struct Bob *);
  27.  
  28. void main(void) {
  29.   struct Picture *bobpic;
  30.   struct Picture *background;
  31.  
  32.   WORD WormFrames[] = {
  33.       0,0,  32,0, 64,0,  96,0, 128,0, 160,0, 192,0, 224,0,
  34.     256,0, 288,0, 0,48, 32,48, 64,48,
  35.     -1,-1
  36.   };
  37.  
  38.   if (AllocBlitter() == ERR_OK) {
  39.    if (AllocAudio() == ERR_OK) {
  40.     if (background = LoadPicFile("GMS:demos/data/PIC.Green",GETPALETTE|VIDEOMEM)) {
  41.  
  42.      if (screen = GetScreen()) {
  43.         CopyStructure(background,screen);
  44.         screen->MemPtr1 = background->Data;
  45.         screen->Attrib  = DBLBUFFER;
  46.  
  47.       if (AddScreen(screen)) {
  48.          CopyBuffer(screen,BUFFER1,BUFFER2);
  49.  
  50.        if (restore = InitRestore(screen,0,1)) {
  51.  
  52.           bobpic = GetPicture();
  53.           CopyStructure(background,bobpic);
  54.           bobpic->Options = VIDEOMEM;
  55.           bobpic->File    = "GMS:demos/data/PIC.Rambo";
  56.  
  57.         if (LoadPic(bobpic)) {
  58.  
  59.          if (Worm = InitBobTags(screen,TAGS_BOB,NULL,
  60.             BBA_GfxCoords,WormFrames,
  61.             BBA_Width,32,
  62.             BBA_Height,24,
  63.             BBA_XCoord,150,
  64.             BBA_YCoord,150,
  65.             BBA_Attrib,RESTORE|GENMASKS|CLIP,
  66.             BBA_Picture,bobpic,
  67.             TAGEND)) {
  68.  
  69.            ShowScreen(screen); 
  70.            Demo();
  71.          }
  72.         }
  73.        }
  74.       }
  75.      }
  76.     if (Worm)       { FreeBob(Worm);        Worm = NULL; }
  77.     if (bobpic)     { FreePic(bobpic);      bobpic = NULL; }
  78.     if (restore)    { FreeRestore(restore); restore = NULL; }
  79.     if (screen)     { DeleteScreen(screen); screen = NULL; } 
  80.     if (background) { FreePic(background);  background = NULL; }
  81.     }
  82.    FreeAudio(); 
  83.    }
  84.   FreeBlitter(); 
  85.   }
  86. }
  87.  
  88. /*=========================================================================*/
  89.  
  90. void Demo(void)
  91. {
  92.   ULONG mouse=0; 
  93.   UWORD anim=0,fire=FALSE;
  94.  
  95.   InitJoyPorts(); 
  96.  
  97.   do
  98.   {
  99.     Restore(screen->Bitmap); 
  100.     DrawBob(Worm); 
  101.     WaitVBL(); 
  102.     SwapBuffers(screen);
  103.  
  104.     /* Animate the Worm's movements */
  105.  
  106.     anim++;
  107.  
  108.     if (fire == FALSE) {
  109.       if (anim > 5) {
  110.         anim = 0;
  111.         Worm->Frame++;
  112.         if (Worm->Frame > 9)
  113.            Worm->Frame = 0;
  114.       }
  115.     }
  116.     else if (anim > 1) {
  117.       anim = 0;
  118.       if (Worm->Frame < 10)
  119.          Worm->Frame = 9;
  120.  
  121.       Worm->Frame++;
  122.  
  123.       if (Worm->Frame > 12) {
  124.          if (mouse & MB_LMB)
  125.             Worm->Frame = 11;
  126.          else {
  127.             Worm->Frame = 0;
  128.             fire = FALSE;
  129.          }
  130.       }
  131.     }
  132.  
  133.     /* Get the user input, wrap the bob around if  */
  134.  
  135.     mouse = ReadJoyPort(JPORT1,JT_ZBXY);
  136.     Worm->XCoord += GetX(mouse);
  137.     Worm->YCoord += GetY(mouse);
  138.     Wrap(Worm);
  139.  
  140.     if (mouse & MB_LMB)
  141.        fire = TRUE;
  142.  
  143.   } while (!(mouse & MB_RMB)); 
  144. }
  145.  
  146. /*****************************************************************************
  147. ** Function: This function will wrap a bob to the other side of a screen if
  148. **           it leaves the bob's screen borders.
  149. **
  150. ** Synopsis: Wrap(Bob);
  151. */
  152.  
  153. void Wrap(struct Bob *bob)
  154. {
  155.   if (bob->XCoord < -bob->Width)
  156.      bob->XCoord = bob->Bitmap->Width;
  157.   if (bob->XCoord > bob->Bitmap->Width)
  158.      bob->XCoord = -bob->Width;
  159.   if (bob->YCoord < -bob->Height)
  160.      bob->YCoord = bob->Bitmap->Height;
  161.   if (bob->YCoord > bob->Bitmap->Height)
  162.      bob->YCoord = -bob->Height;
  163. }
  164.  
  165.